# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>

pkgname=libredefender
pkgver=0.6.0
pkgrel=2
pkgdesc='Light-weight antivirus scanner for Linux'
url='https://github.com/kpcyrd/libredefender'
arch=('loong64' 'x86_64')
license=('GPL2')
depends=('libclamav.so' 'hicolor-icon-theme')
makedepends=('cargo' 'clang')
source=(https://github.com/kpcyrd/${pkgname}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
        https://github.com/kpcyrd/${pkgname}/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.gz.asc
        clamav-1.0.patch)
b2sums=('fba45c42842220c0b43a06c56fbecbaa093819715822a9e673570c21b21a2cd6b9cba72711d76758bbbadb542b4a8d356f1107020593d74b12a7ad581c3ed562'
        'SKIP'
        'bc44726d294e500b032da217d10cd23aca2dccbeec124e3696558a5d331c182ab3bc431d74f3dcdbea1686c0cbec32ee8d9240e0de22fdf5be2c31bd116afdee')

validpgpkeys=("64B13F7117D6E07D661BBCE0FE763A64F5E54FD6")

prepare() {
  cd "${pkgname}-${pkgver}"
  patch -i ../clamav-1.0.patch
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd ${pkgname}-${pkgver}
  cargo build --frozen --release
}

check() {
  cd ${pkgname}-${pkgver}
  cargo test --frozen
}

package() {
  cd ${pkgname}-${pkgver}
  install -Dm 755 -t "${pkgdir}/usr/bin" \
    target/release/libredefender

  # install completions
  install -d "${pkgdir}/usr/share/bash-completion/completions" \
             "${pkgdir}/usr/share/zsh/site-functions" \
             "${pkgdir}/usr/share/fish/vendor_completions.d"
  "${pkgdir}/usr/bin/libredefender" completions bash > "${pkgdir}/usr/share/bash-completion/completions/libredefender"
  "${pkgdir}/usr/bin/libredefender" completions zsh > "${pkgdir}/usr/share/zsh/site-functions/_libredefender"
  "${pkgdir}/usr/bin/libredefender" completions fish > "${pkgdir}/usr/share/fish/vendor_completions.d/libredefender.fish"

  install -Dm 644 contrib/libredefender.desktop -t "${pkgdir}/etc/xdg/autostart"
  install -Dm 644 contrib/icon.svg "${pkgdir}/usr/share/icons/hicolor/scalable/apps/${pkgname}.svg"
  install -Dm 644 LICENSE-* -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim: ts=2 sw=2 et:
